package com.nowcoder.code.hjnc;

import java.util.ArrayList;

public class NC55 {

    public String longestCommonPrefix(String[] strs) {

        if (strs.length == 0) {
            return "";
        }


        char[] cs = strs[0].toCharArray();
        int min = cs.length;

        for (int i = 1; i < strs.length; i++) {

            if (strs[i].length() < min) {
                min = strs[i].length();
            }
            for (int j = 0; j < min; j++) {
                if (cs[j] != strs[i].charAt(j)) {
                    min = j;
                    break;
                }
            }

        }
        return new String(cs, 0, min);

    }

    public static void main(String[] args) {
        String[] ss = {"abca", "abc", "abca", "abc", "abcc"};
        System.out.println(new NC55().longestCommonPrefix(ss));

    }

}
